<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of incidence_matrix</title>
  <meta name="keywords" content="incidence_matrix">
  <meta name="description" content="incidence_matrix(g) --- return the vertex/edge incidence matrix.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; incidence_matrix.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>incidence_matrix
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>incidence_matrix(g) --- return the vertex/edge incidence matrix.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function M = incidence_matrix(g,type) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> incidence_matrix(g) --- return the vertex/edge incidence matrix.
 The matrix returned is always sparse. 

 We return an nv-by-ne matrix whose ij entry is 1 if vertex i is an
 end point of edge j.

 Optional: incidence_matrix(g,'signed') which is the same matrix but one
 entry in each column is negative and one is negative.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="edges.html" class="code" title="function elist = edges(g)">edges</a>	edges(g) --- list the edges in g as a 2-column matrix</li><li><a href="size.html" class="code" title="function [sz,tz] = size(g)">size</a>	size(g) --- returns [nv,ne] for the graph</li><li><a href="sparse.html" class="code" title="function sparse(g)">sparse</a>	sparse(g) --- convert internal storage for g to sparse</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="alpha.html" class="code" title="function [a,S] = alpha(g)">alpha</a>	[a,S] = alpha(g) --- indepencence number</li><li><a href="bridges.html" class="code" title="function blist = bridges(g,algo)">bridges</a>	bridges(g,algo) --- find all cut edges in g</li><li><a href="color.html" class="code" title="function p = color(g,algo,max_time)">color</a>	color(g,algo) --- color the graph g by a given algorithm</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function M = incidence_matrix(g,type)</a>
0002 <span class="comment">% incidence_matrix(g) --- return the vertex/edge incidence matrix.</span>
0003 <span class="comment">% The matrix returned is always sparse.</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% We return an nv-by-ne matrix whose ij entry is 1 if vertex i is an</span>
0006 <span class="comment">% end point of edge j.</span>
0007 <span class="comment">%</span>
0008 <span class="comment">% Optional: incidence_matrix(g,'signed') which is the same matrix but one</span>
0009 <span class="comment">% entry in each column is negative and one is negative.</span>
0010 
0011 
0012 
0013 
0014 
0015 [n,m] = <a href="size.html" class="code" title="function [sz,tz] = size(g)">size</a>(g);
0016 e = <a href="edges.html" class="code" title="function elist = edges(g)">edges</a>(g);
0017 
0018 <span class="keyword">if</span> nargin&lt;2
0019     type = <span class="string">'unsigned'</span>;  <span class="comment">% default type</span>
0020 <span class="keyword">end</span>
0021 
0022 signed = false;
0023 
0024 <span class="keyword">switch</span> lower(type)
0025     <span class="keyword">case</span> <span class="string">'signed'</span>
0026         signed = true;
0027     <span class="keyword">case</span> <span class="string">'unsigned'</span>
0028         signed = false;
0029     <span class="keyword">otherwise</span>
0030         error([<span class="string">'Unknown incidence matrix type:'</span>, type]);
0031 <span class="keyword">end</span>
0032 
0033 i = [e(:,1);e(:,2)];
0034 j = [1:m,1:m]';
0035 
0036 <span class="keyword">if</span> signed
0037     k = [ones(m,1);-ones(m,1)];
0038 <span class="keyword">else</span>
0039     k = ones(2*m,1);
0040 <span class="keyword">end</span>
0041 
0042 M = <a href="sparse.html" class="code" title="function sparse(g)">sparse</a>(i,j,k,n,m);</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>